home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / config / m68k / xm-amigados.h < prev    next >
C/C++ Source or Header  |  1995-08-24  |  9KB  |  256 lines

  1. /* Configuration for GNU C-compiler for Commodore Amiga, running AmigaDOS.
  2.    Copyright (C) 1992 Free Software Foundation, Inc.
  3.    Contributed by Markus M. Wild (wild@amiga.physik.unizh.ch).
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* first include the generic header, then modify some parts.. */
  22.  
  23. #include "m68k/xm-m68k.h"
  24.  
  25. /* On the Amiga, there are two pathname separators, '/' (DIR_SEPARATOR)
  26.    and ':' (VOL_SEPARATOR).  DIR_SEPARATOR defaults to the correct
  27.    character, so we don't have to explicitly set it. */
  28.  
  29. #define VOL_SEPARATOR ':'
  30.  
  31. /* Amiga specific headers, such as from the Native Developer Update kits,
  32.    go in SYSTEM_INCLUDE_DIR.  STANDARD_INCLUDE_DIR is the equivalent of
  33.    Unix "/usr/include".  All other include paths are set in Makefile. */
  34.  
  35. #define SYSTEM_INCLUDE_DIR    "/gnu/os-include"
  36. #define STANDARD_INCLUDE_DIR    "/gnu/include"
  37.  
  38. /* Fork one piped subcommand.  SEARCH_FLAG is the system call to use
  39.    (either execv or execvp).  ARGV is the arg vector to use.
  40.    NOT_LAST is nonzero if this is not the last subcommand
  41.    (i.e. its output should be piped to the next one.)  */
  42.  
  43. #ifndef AMIGADOS_FORK_GCC
  44.  
  45. /* This version uses a more or less amigados-conformant way of running a
  46.    program (in the context of the parent). If you want to use -pipe however,
  47.    you'll have to use the vfork() version afterwards.
  48.    Phil.B: 29-May-94 quick hack (number 20 added to length) because xgcc
  49.    doesn't work.
  50.  */
  51.  
  52. #define PEXECUTE(SEARCH_FLAG,PROGRAM,ARGV,NOT_LAST) \
  53. ({char *_argline;                        \
  54.   int _arglinelength, _i;                    \
  55.                                 \
  56.   for (_i = 1, _arglinelength=0; ARGV[_i]; ++_i)        \
  57.     _arglinelength += strlen(ARGV[_i]) + 1;            \
  58.                                 \
  59.   _arglinelength += strlen(PROGRAM) + 20 + 1;            \
  60.                                 \
  61.   if (!(_argline = (char *)alloca(_arglinelength)))         \
  62.     pfatal_with_name ("alloca");                \
  63.                                 \
  64.   strcpy(_argline, PROGRAM);                    \
  65.   for (_i = 1; ARGV[_i]; ++_i)                     \
  66.     {                                \
  67.       strcat(_argline, " ");                    \
  68.       strcat(_argline, ARGV[_i]);                \
  69.     }                                \
  70.                                 \
  71.   ssystem(_argline); })                        \
  72.  
  73. #define PEXECUTE_RESULT(STATUS, COMMAND) \
  74.   ({ STATUS = COMMAND.pid; })
  75.  
  76. #else
  77.  
  78. /* the vfork() version. This one has the drawback, that gcc is not 
  79.    interruptible when started from make, since ixemul.library doesn't yet
  80.    propagate ^C to subprocesses. */
  81.  
  82. #define PEXECUTE(SEARCH_FLAG,PROGRAM,ARGV,NOT_LAST) \
  83. ({int (*_func)() = (SEARCH_FLAG ? execv : execvp);            \
  84.   int _pid;                                \
  85.   int _pdes[2];                                \
  86.   int _input_desc = last_pipe_input;                    \
  87.   int _output_desc = STDOUT_FILE_NO;                    \
  88.   int _retries, _sleep_interval, _result;                \
  89.                                     \
  90.   /* If this isn't the last process, make a pipe for its output,    \
  91.      and record it as waiting to be the input to the next process.  */    \
  92.                                     \
  93.   if (NOT_LAST)                                \
  94.     {                                    \
  95.       if (pipe (_pdes) < 0)                        \
  96.     pfatal_with_name ("pipe");                    \
  97.       _output_desc = _pdes[WRITE_PORT];                    \
  98.       last_pipe_input = _pdes[READ_PORT];                \
  99.     }                                    \
  100.   else                                    \
  101.     last_pipe_input = STDIN_FILE_NO;                    \
  102.                                     \
  103.   /* Fork a subprocess; wait and retry if it fails.  */            \
  104.   _sleep_interval = 1;                            \
  105.   for (_retries = 0; _retries < 4; _retries++)                \
  106.     {                                    \
  107.       _pid = vfork ();                            \
  108.       if (_pid >= 0)                            \
  109.     break;                                \
  110.       sleep (_sleep_interval);                        \
  111.       _sleep_interval *= 2;                        \
  112.     }                                    \
  113.                                     \
  114.   switch (_pid)                                \
  115.     {                                    \
  116.     case -1:                                \
  117.       pfatal_with_name ("vfork");                    \
  118.       /* NOTREACHED */                            \
  119.       _result = 0;                            \
  120.       break;                                \
  121.                                     \
  122.     case 0: /* child */                            \
  123.       /* Move the input and output pipes into place, if nec.  */    \
  124.       if (_input_desc != STDIN_FILE_NO)                    \
  125.     {                                \
  126.       close (STDIN_FILE_NO);                    \
  127.       dup (_input_desc);                        \
  128.       close (_input_desc);                        \
  129.     }                                \
  130.       if (_output_desc != STDOUT_FILE_NO)                \
  131.     {                                \
  132.       close (STDOUT_FILE_NO);                    \
  133.       dup (_output_desc);                        \
  134.       close (_output_desc);                        \
  135.     }                                \
  136.                                     \
  137.       /* Close the parent's descs that aren't wanted here.  */        \
  138.       if (last_pipe_input != STDIN_FILE_NO)                \
  139.     close (last_pipe_input);                    \
  140.                                     \
  141.       /* Exec the program.  */                        \
  142.       (*_func) (PROGRAM, ARGV);                        \
  143.       perror_exec (PROGRAM);                        \
  144.       exit (-1);                            \
  145.       /* NOTREACHED */                            \
  146.       _result = 0;                            \
  147.       break;                                \
  148.                                     \
  149.     default:                                \
  150.       /* In the parent, after forking.                    \
  151.      Close the descriptors that we made for this child.  */        \
  152.       if (_input_desc != STDIN_FILE_NO)                    \
  153.     close (_input_desc);                        \
  154.       if (_output_desc != STDOUT_FILE_NO)                \
  155.     close (_output_desc);                        \
  156.                                     \
  157.       /* Return child's process number.  */                \
  158.       _result = _pid;                            \
  159.       break;                                \
  160.     }                                     \
  161. _result; })                                \
  162.  
  163. #define PEXECUTE_RESULT(STATUS, COMMAND) \
  164.   ({ wait (& STATUS); })
  165.  
  166. #endif /* AMIGADOS_FORK_GCC */
  167.  
  168. /* the following macros are stolen more or less from xm-vms.h ... */
  169.  
  170. /* This macro is used to help compare filenames in cp-lex.c.
  171.  
  172.    We also need to make sure that the names are all lower case, because
  173.    we must be able to compare filenames to determine if a file implements
  174.    a class.  */
  175.  
  176. #define FILE_NAME_NONDIRECTORY(C)                \
  177. ({                                \
  178.    extern char *rindex();                    \
  179.    char * pnt_ = (C), * pnt1_;                    \
  180.    pnt1_ = pnt_ - 1;                        \
  181.    while (*++pnt1_)                        \
  182.      if ((*pnt1_ >= 'A' && *pnt1_ <= 'Z')) *pnt1_ |= 0x20;    \
  183.    pnt1_ = rindex (pnt_, '/');                     \
  184.    pnt1_ = (pnt1_ == 0 ? rindex (pnt_, ':') : pnt1_);        \
  185.    (pnt1_ == 0 ? pnt_ : pnt1_ + 1);                \
  186.  })
  187.  
  188. /* Macro to generate the name of the cross reference file.  The standard
  189.    one does not work, since it was written assuming that the conventions
  190.    of a unix style filesystem will work on the host system.
  191.  
  192.    Contrary to VMS, I'm using the original unix filename, there's no reason
  193.    not to use this under AmigaDOS. */
  194.  
  195. #define XREF_FILE_NAME(BUFF, NAME)    \
  196.   s = FILE_NAME_NONDIRECTORY (NAME);            \
  197.   if (s == NAME) sprintf(BUFF, ".%s.gxref", NAME);    \
  198.   else {                        \
  199.     unsigned char ch = *s; /* could be Latin1 char.. */    \
  200.     /* temporary: cut the filename from the directory */\
  201.     *s = 0;                        \
  202.     sprintf (BUFF, "%s.%c%s.gxref", NAME, ch, s+1);    \
  203.     /* and restore the filename */            \
  204.     *s = ch;                        \
  205.   }                            \
  206.  
  207. /* Macro that is used in cp-xref.c to determine whether a file name is
  208.    absolute or not.
  209.  
  210.    This checks for both, '/' as first character, since we're running under
  211.    ixemul.library which provides for this unix'ism, and for the usual 
  212.    logical-terminator, ':', somewhere in the filename. */
  213.  
  214. #define FILE_NAME_ABSOLUTE_P(NAME) (NAME[0] == '/' || index(NAME, ':'))
  215.  
  216. /* the colon conflicts with the name space of logicals */
  217.  
  218. #define PATH_SEPARATOR ','
  219.  
  220. /* AmigaDOS handles rename(2) *much* better than any link(2)/unlink(2)
  221.    hacks. It's actually the inverse case as on Unix. rename(2) was always
  222.    there, link(2) is new with OS 2.0 */
  223.  
  224. #define HAVE_rename 1
  225.  
  226. /* Phil.B 17-Apr-95 Added stack checking code submitted by Kriton Kyrimis
  227.    (kyrimis@theseas.ntua.gr) on 10-Feb-95, modified for inclusion into gcc
  228.  
  229.    What stackcheck does is to add the following code at the beginning of
  230.    each function:
  231.     cmpl __StackBottom,sp
  232.     bccs .+8
  233.     jmp __StackOverflow
  234.  
  235.    _StackBottom and _StackOverflow() are defined in stackchecksetup.c.
  236.    _StackBottom is set to the bottom of the stack plus some leeway for
  237.    subroutine arguments (128 bytes).  _StackOverflow() sets the stack
  238.    pointer to a sane value, prints an error message and exits.
  239.  
  240.    Even with stack checking, you cannot be completely safe, as overflows
  241.    are detected on function entry, rather than during function execution.
  242.    E.g.,
  243.     crash(){
  244.       char scribble[100000];
  245.       int i;
  246.       for (i=0; i<100000; i++) scribble[i]=0;
  247.       check(scribble);
  248.     }
  249.     check(char *x){}
  250.    In the above example, stack overflow and its side-effects will occur in
  251.    crash(), but it will be detected in check(), when it is too late. (The
  252.    same thing happens with SAS/C's stack checking, BTW.)
  253. */
  254.  
  255. /* #defined AMIGA_STACK_CHECKING */
  256.